import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/animate/eg_Hero.dart';
import 'package:flutter_app/animate/eg_animated_opacity.dart';
import 'package:flutter_app/decorate/eg_opacity.dart';
import 'package:flutter_app/layout/ed_ConstrainedBox.dart';
import 'package:flutter_app/layout/eg_Align.dart';
import 'package:flutter_app/layout/eg_AspectRatio.dart';
import 'package:flutter_app/layout/eg_Column.dart';
import 'package:flutter_app/layout/eg_FittedBox.dart';
import 'package:flutter_app/layout/eg_FractionallySizedBox.dart';
import 'package:flutter_app/layout/eg_IndexStack.dart';
import 'package:flutter_app/layout/eg_LimitedBox.dart';
import 'package:flutter_app/layout/eg_OverflowBox.dart';
import 'package:flutter_app/layout/eg_Row.dart';
import 'package:flutter_app/layout/eg_SizedBox.dart';
import 'package:flutter_app/layout/eg_Stack.dart';
import 'package:flutter_app/list/eg_GirdView.dart';
import 'package:flutter_app/list/eg_TableView.dart';
import 'package:flutter_app/list/eg_listView.dart';
import 'package:flutter_app/other/eg_Baseline.dart';
import 'package:flutter_app/other/eg_Offstage.dart';
import 'package:flutter_app/other/eg_Transform.dart';
import 'package:flutter_app/other/eg_Wrap.dart';
import 'package:flutter_app/pack_gestureDetector/eg_Dismissible.dart';
import 'package:flutter_app/pack_gestureDetector/eg_GestureDetector.dart';
import 'package:flutter_app/router/eg_router.dart';
import 'package:flutter_app/router/eg_router_with_data.dart';
import 'package:flutter_plugin/flutter_plugin.dart';

class ScaffoldDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: Text("Scaffold 组件演示")),
      body: new Center(
        child: new SingleChildScrollView(
          child: Column(
            children: <Widget>[
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/EgContainer");
                },
                child: Text("跳转到Container演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/EgCenter");
                },
                child: Text("跳转到Center布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.pushNamed(context, "/EgPadding");
                },
                child: Text("跳转到Padding布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgAlign();
                  }));
                },
                child: Text("跳转到Align布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgRow();
                  }));
                },
                child: Text("跳转到Row布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgColumn();
                  }));
                },
                child: Text("跳转到Column布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgFittedBox();
                  }));
                },
                child: Text("跳转到FittedBox布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgStackWithAlignment();
                  }));
                },
                child: Text("跳转到对其折叠布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgStackWithPosition();
                  }));
                },
                child: Text("跳转到位置折叠布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgIndexedStack();
                  }));
                },
                child: Text("跳转到索引折叠布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgOverflowBox();
                  }));
                },
                child: Text("跳转溢出布局演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgSizedBox();
                  }));
                },
                child: Text("固定尺寸组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgConstrainedBox();
                  }));
                },
                child: Text("限定组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgLimitedBox();
                  }));
                },
                child: Text("最大限定组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgAspectRation();
                  }));
                },
                child: Text("宽高比例限定组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgFractionallySizedBox();
                  }));
                },
                child: Text("百分比比例限定组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgListView();
                  }));
                },
                child: Text("listView组件演示页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgListText();
                  }));
                },
                child: Text("listView组件长文本使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgListViewBuild();
                  }));
                },
                child: Text("listView组件Builder使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgGridView();
                  }));
                },
                child: Text("网格布局组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgTableView();
                  }));
                },
                child: Text("表格布局组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgTransform();
                  }));
                },
                child: Text("矩阵转换组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgBaseLine();
                  }));
                },
                child: Text("基准线组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgOffstage();
                  }));
                },
                child: Text("隐藏显示组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgWrap();
                  }));
                },
                child: Text("换行组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgGestureDetector();
                  }));
                },
                child: Text("手势组件使用页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgDismissible();
                  }));
                },
                child: Text("滑动删除页面", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgRouterTest();
                  }));
                },
                child: Text("路由跳转", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgRouterWithData();
                  }));
                },
                child: Text("路由跳转传参", style: Theme.of(context).textTheme.button),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgOpacity();
                  }));
                },
                child: new Center(
                  child: Text("不透明度设置", style: Theme.of(context).textTheme.button),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgAnimatedOpacity();
                  }));
                },
                child: new Center(
                  child: Text("淡隐淡显设置", style: Theme.of(context).textTheme.button),
                ),
              ),
              RaisedButton(
                onPressed: () {
                  Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) {
                    return EgHero();
                  }));
                },
                child: new Center(
                  child: Text("转场动画演示", style: Theme.of(context).textTheme.button),
                ),
              ),
              new PluginTest(),
              Text("测试各种布局", style: Theme.of(context).textTheme.button),
            ],
          ),
        ),
      ),
      bottomNavigationBar: new BottomAppBar(
        child: Container(
          height: 50,
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: () {
          print('FloatingActionButton');
        },
        tooltip: "增加",
        child: new Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}

class PluginTest extends StatelessWidget {
  Future<String> _getPwd(BuildContext context) async {
    try {
      var pwd = await FlutterPlugin.userPwd;
      Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(pwd)));
      return pwd;
    } on PlatformException {}
    return "没有获取到";
  }

  @override
  Widget build(BuildContext context) {
    return new RaisedButton(
      onPressed: () {
        _getPwd(context);
      },
      child: new Center(
        child: Text("通过插件获取密码", style: Theme.of(context).textTheme.button),
      ),
    );
  }
}
